package test.AcceptanceTests;

import BusinessLogic.ControllerFacade;
import BusinessLogic.Exceptions.AuthenticationFailedException;
import BusinessLogic.Exceptions.DataAlreadyExistException;
import BusinessLogic.Exceptions.UserAlreadyExistException;
import BusinessLogic.Exceptions.MovieNotExistException;
import junit.framework.TestCase;
import Domain.Exceptions.UserNotLoggedInException;

import java.util.Collection;


public abstract class ProjectTestBridge extends  TestCase{
    ControllerFacade controller;
    
    public ProjectTestBridge(String string) {
        super(string);
    }

    public void setUp(){
        controller = new ControllerFacade(); 
    }
    
    public boolean login(String name, String password){
        try {
           controller.login(name,password);
        }
        catch (Exception e) {
            return false;
        }
        return true;
    }

    public boolean logout(String name){
        try {
           controller.logout();
        }
        catch (Exception e) {
           // e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            return false;
        }
        return true;
    }

    public String getCurrentUser(){
        try {
           return controller.getCurrentUser().getUsername();
        }
        catch (Exception e) {
            //e.printStackTrace();
            return null;
        }
    }

    public boolean addMovie(String name,String director,String year,int length,String country, String genres,String actors){
        try {
            controller.addNewMovie(name,director,year,length,country,genres,actors);
        } catch (DataAlreadyExistException e) {
            e.printStackTrace();
            return false;
        }
        return controller.existMovie(name);
    }
    public boolean deleteMovie(String name){
        controller.deleteMovie(name);
        return true; 
    }

    public boolean addNewUser(String username, String firstname, String lastname, String password, String VIP, String email, String acl){
        try{
            controller.addNewUser(username,  firstname,  lastname,  password,  VIP,  email, acl);
        }
        catch (UserAlreadyExistException e) {
            e.printStackTrace();
            return false;
        }
        catch (AuthenticationFailedException e) {
            e.printStackTrace();
            return false;
        }
        return controller.existUser(username);
    }
    public boolean deleteUser(String username){
        controller.deleteUser(username);
        return true;
    }

    public boolean addMovieRecommendation(String moviename, int rank, String freetext){
        try{
            controller.addMovieRecommendation(moviename, rank, freetext);
        } catch (MovieNotExistException e) {
            e.printStackTrace();
            return false;
        } catch (UserNotLoggedInException e) {
            e.printStackTrace();
            return false;
        }
        return  controller.existRecommendation(moviename);
    }


     public Collection<String> getAllMovies() {
         return controller.getAllMovies();
     }

     public Collection<String> getOnlineUsers(){
         return controller.getOnlineUsers();
     }
}
